package com.lightheart.sphr.xiaobinggan.fragment;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.MotionEvent;
import android.view.View;

import com.lightheart.sphr.xiaobinggan.R;
import com.lightheart.sphr.xiaobinggan.base.BaseFragment;
import com.lightheart.sphr.xiaobinggan.design.adapter.Adapter_Diary;
import com.lightheart.sphr.xiaobinggan.module.main.ui.MainActivity;
import com.lightheart.sphr.xiaobinggan.timeselection.uitls.CustomToastUtils;

import java.util.ArrayList;

public class FragmentTwo extends BaseFragment implements MainActivity.FragmentTouchListener {

    private RecyclerView mRecyclerView;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_two_layout;
    }

    @Override
    protected void initInjector() {

    }

    public static FragmentTwo newInstance() {
        return new FragmentTwo();
    }

    @Override
    protected void initView(View view) {
        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
        mRecyclerView = view.findViewById(R.id.rec);
        mRecyclerView.setLayoutManager(layoutManager);
        initList();
        ((MainActivity) this.getActivity()).registerFragmentTouchListener(this);
    }

    private void initList() {
        ArrayList<String> dataList = new ArrayList<>();
        for (int i = 0; i < 20; i++) {
            dataList.add("日记" + i);
        }
        Adapter_Diary mAdapter = new Adapter_Diary(dataList);
        mRecyclerView.setAdapter(mAdapter);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        ((MainActivity) this.getActivity()).unRegisterFragmentTouchListener(this);
    }

    @Override
    public void onDetach() {
        super.onDetach();
        ((MainActivity) this.getActivity()).unRegisterFragmentTouchListener(this);
    }


    @Override
    public boolean onTouchEvent(MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:  //有按下动作时取消定时
                CustomToastUtils.INSTANCE.imgToast("按下动作", "good");
                break;
            case MotionEvent.ACTION_UP:    //抬起时启动定时
                CustomToastUtils.INSTANCE.imgToast("抬起动作", "good");
                break;
            default:
                break;
        }
        return false;
    }
}
